/*
 * @Author: 晟松
 * @Date: 2021-12-07 20:03:23
 * @LastEditors: 晟松
 * @LastEditTime: 2022-02-04 16:55:03
 * @FilePath: \mini-vue3d:\Code\node\koa2\volunteer-service\src\main\model\School.js
 * @Description: 辅导员的model
 */
import Sequelize from "sequelize";
import {  isValidateEnum } from "@main/util/ValidateUtil";
import { ParamError } from "../common/CommonError";
import enums from "@main/config/enums";

export const modelName = "school";

const DataTypes = Sequelize.DataTypes;

export const attributes = {
    identity: {
        type: DataTypes.INTEGER,
        validate:{
            check(val){
                if(val!=enums['identity']['school']){
                    throw new ParamError(`identity school: ${val}值错误`);
                }
            }
        }
    },
    userName: {
        type: DataTypes.STRING,
    },
    avatar: {
        type: DataTypes.STRING,
    },
    gender: {
        type: DataTypes.INTEGER,
        validate: {
            check(val) {
                if (!isValidateEnum(val, "gender")) {
                    throw new ParamError(`gender: ${val}值错误`);
                }
            },
        },
    },
    schoolName: {
        type: DataTypes.STRING,
    },
    // 只指定类型时的缩写
    college: DataTypes.STRING,
    grade:{
        type:DataTypes.INTEGER,
        validate:{
            check(val) {
                if (!isValidateEnum(val, "grade")) {
                    throw new ParamError(`grade: ${val}值错误`);
                }
            },
        }
    },
    introduction:DataTypes.STRING,
    managementLevel:{
        type:DataTypes.INTEGER,
        validate:{
            check(val){
                if (!isValidateEnum(val, "managementLevel")) {
                    throw new ParamError(`managementLevel: ${val}值错误`);
                }
            }
        }
    },
    available: DataTypes.BOOLEAN, // 主要是院级辅导员需要被校级管理员审核
    // 这两个是关于区块链的一个记录，主要是记录其中的交易hash和块hash，通过这两个hash就可从区块链中获取到对应的信息
    transactionHash: DataTypes.STRING,
    blockHash: DataTypes.STRING,
};

export const options = {
    // tableName: "t_user_reference",
};
